package com.example.com.common.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.TextView;
import android.widget.Toast;

import com.example.com.common.R;


public class ToastUtil {
    private static Toast sToast;

    private static void showToast(Context context, String msg, int duration) {
        if (sToast == null) {
            Context appContext = context.getApplicationContext();
            sToast = new Toast(appContext);
            TextView textView = (TextView) LayoutInflater.from(appContext).inflate(R.layout.layout_toast, null);
            textView.setMaxWidth((int) (ScreenUtils.getScreenWidth() * 0.9));
            sToast.setView(textView);
        }
        sToast.setDuration(duration);
        TextView tv = (TextView) sToast.getView();
        tv.setText(msg);
        sToast.show();
    }

    public static void showToastLong(Context context, String msg) {
        showToast(context, msg, Toast.LENGTH_LONG);
    }

    public static void showToastShort(Context context, String msg) {
        showToast(context, msg, Toast.LENGTH_SHORT);
    }

    public static void showToastLong(Context context, int resId) {
        showToast(context, context.getResources().getString(resId), Toast.LENGTH_LONG);
    }

    public static void showToastShort(Context context, int resId) {
        showToast(context, context.getResources().getString(resId), Toast.LENGTH_SHORT);
    }



}
